<template>
	<view style="background-color: #fff;">
		<view class="container">
			<uni-section title="基本用法" type="line">
				<view class="form">
					<!-- 基础用法，不包含校验规则 -->
					<uni-forms ref="form" :modelValue="form">
						<uni-forms-item label="申请人用户名" required>
							<uni-easyinput v-model="form.username" placeholder="请输入申请人用户名" />
						</uni-forms-item>
						<uni-forms-item label="请假时长" required>
							<uni-easyinput v-model="form.duration" placeholder="请输入请假时长，单位：天" />
						</uni-forms-item>
						<uni-forms-item label="工作委托人" required>
							<uni-easyinput v-model="form.principal" placeholder="请输入工作委托人" />
						</uni-forms-item>
						<uni-forms-item label="联系电话" required>
							<uni-easyinput v-model="form.contactPhone" placeholder="请输入联系电话" />
						</uni-forms-item>
						<uni-forms-item label="标题" required>
							<uni-easyinput v-model="form.title" placeholder="请输入标题" />
						</uni-forms-item>
						<uni-forms-item label="请假开始时间">
							<uni-datetime-picker type="datetime" return-type="timestamp" v-model="form.startDate" />
						</uni-forms-item>
						<uni-forms-item label="请假结束时间">
							<uni-datetime-picker type="datetime" return-type="timestamp" v-model="form.endDate" />
						</uni-forms-item>
					</uni-forms>
				</view>
			</uni-section>
		</view>
		<!-- 按钮 -->
		<processButton @submit="submit" @staging="staging" :parentTaskId="parentTaskId" :isClaim="isClaim"
			@claimCallBack="claimCallBack" @returnCallBack="returnCallBack" :taskId="taskId"
			:processInstanceId="processInstanceId">
		</processButton>
		<!-- 审批组件 -->
		<verify :taskId="taskId" :taskVariables="taskVariables" :sendMessage="sendMessage"
			@submitCallback="submitCallback" ref="verifyRef" />
	</view>
</template>

<script>
	import processButton from '@/components/process/process-button/process-button.vue'
	import verify from '@/components/process/verify/verify.vue'
	import taskApi from "@/api/workflow/task.js"
	import {
		getTaskLeave
	} from "@/api/demo/leave";
	export default {
		components: {
			processButton,
			verify
		},
		data() {
			return {
				// 列表数据
				list: [],
				// 总条数
				total: 0,
				// 表单参数
				form: {},
				type: 'center',
				taskId: '',
				taskVariables: {},
				// 消息提醒
				sendMessage: {},
				// 流程定义key
				processDefinitionKey: '',
				//是否认领
				isClaim: null,
				//父级任务是否为空
				parentTaskId: null,
				//流程示实例id
				processInstanceId: ''
			}
		},
		created() {
			this.taskId = this.$route.query.taskId
			this.processDefinitionKey = this.$route.query.processDefinitionKey
			this.getById();
		},
		methods: {
			// 查询
			getById() {
				getTaskLeave(this.$route.query.businessKey, this.taskId).then(res => {
					this.form = res.data
					if (res.data && res.data.actBusinessStatus) {
						this.processInstanceId = res.data.actBusinessStatus.processInstanceId
					}
					if (res.data.currentTask && res.data.currentTask !== null) {
						this.isClaim = res.data.currentTask.isClaim
						this.parentTaskId = res.data.currentTask.parentTaskId
					}
				})
			},
			//提交
			submit() {
				this.sendMessage = {
					title: '请假申请',
					messageContent: '单据【' + this.form.id + "】申请"
				}
				this.$refs.verifyRef.open()
			},
			// 暂存
			staging() {
				this.$tab.navigateTo('/pages/workflow/waiting/waiting?processDefinitionKey=' + this.processDefinitionKey)
			},
			// 提交成功回调
			submitCallback(processDefinitionKey) {
				this.$tab.navigateTo('/pages/workflow/waiting/waiting?processDefinitionKey=' + processDefinitionKey)
			},
			//签收成功回调
			claimCallBack() {
				this.getById()
			},
			//归还成功回调
			returnCallBack() {
				this.getById()
			}
		}
	}
</script>

<style scoped>
	.container {
		padding: 10rpx;
		height: 88vh;
		overflow-y: auto;
	}

	uni-button {
		width: 180rpx;
		height: 65rpx;
		line-height: 65rpx;
		font-size: 28rpx;
	}
</style>
